package com.wxh.boot.controller;

import com.wxh.boot.properties.SystemProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Spring boot 控制器
 *
 * @author wxh
 * @date：2017.09.17
 */

@RestController
@RequestMapping("/hello")
public class HelloController {

    @Autowired
    private SystemProperties system;

    /**
     * RequestMapping 支持集合映射
     * GET/POST 方式最好是定义出来，不推荐两种兼容模式
     * 或者使用GetMapping PostMapping
     */
    @RequestMapping(value = {"/say", "/hi"}, method = RequestMethod.GET)
    public String say(@RequestParam(value = "name", required = false, defaultValue = "") String name) {
        if (name == null || "".equals(name)) {
            return  "Hello spring-boot!";
        }
        return  "Hello " + name + ", this is spring-boot!";
    }

    @RequestMapping(value = "/say/{name}", method = RequestMethod.GET)
    public String sayHello(@PathVariable("name") String name) {
        return "Hello " + name + ", this is spring-boot!";
    }

    @RequestMapping(value = "/system", method = RequestMethod.GET)
    public String printSystem() {
        return system.toString();
    }
}